#include"server.hpp"
#define HOST "127.0.0.1"//mysql默认情况下是不允许用户进行远程登陆的，所以用公网地址是访问不了的，所以用本地环回的ip
#define PORT 3306
#define USER "root"
#define PASS "zhh@Mysql0.0"
#define DBNAME "gobang"

void mysql_test()
{   
    MYSQL * mysql =mysql_util::mysql_create(HOST,USER,PASS,DBNAME,PORT);
    const char *sql ="insert stu value(null,'小黑',18,53,66,88)";
    
    bool ret =mysql_util::mysql_exec(mysql,sql);
    if(ret ==false) return ;

    mysql_util::mysql_destroy(mysql);
}
void json_test()
{
    Json::Value root;
    std::string body;
    root["姓名"]="小明";
    root["年龄"] = 18;
    root["成绩"].append(98);
    root["成绩"].append(88.5);
    root["成绩"].append(78.5);
    json_util::serialize(root,body);
    DLOG("%s",body.c_str());

    Json::Value val;
    json_util::deserialize(val,body);
    std::cout << "姓名:" << val["姓名"].asString()  << std::endl;
    std::cout << "年龄:" << val["年龄"].asInt()  << std::endl;
    int sz = val["成绩"].size();
    for (int i = 0; i < sz; i++) {
        std::cout << "成绩: " << val["成绩"][i].asFloat() << std::endl;
    }

}
void str_test()
{
    std::string str ="123,23,,,,,2331";
    std::vector<std::string> arry;
    string_util::split(str,",",arry);
    for(auto& x:arry)
    {
        DLOG("%s",x.c_str());
    }

}
void file_test()
{
    std::string filename="./makefile";
    std::string body;
    file_util::read(filename,body);
    std::cout<<body<<std::endl;
}
void db_test()
{
    user_table db(HOST,USER,PASS,DBNAME,PORT);
    Json::Value user;
    user["username"]="abc";
    // user["password"]="123456";
    db.insert(user);
    bool ret=db.login(user);
    if(!ret)
    {
        DLOG("LOGIN FAILED");
        return;
    }

    //测试获取数据
    // db.select_by_id(2,user);
    // std::string body;
    // json_util::serialize(user,body);
    // DLOG("%s",body.c_str());

    //测试胜负
    // db.win(1);
    // db.lose(1);
}
void online_manage_test()
{
    online_manager om;
    wsserver_t::connection_ptr conn;
    uint64_t uid=2;
    om.enter_game_hall(2,conn);
    if(om.is_in_game_hall(uid)) DLOG("IN GAME HALL");
    else DLOG("NOT IN GAME HALL");

    om.exit_game_hall(uid);
    if(om.is_in_game_hall(uid)) DLOG("IN GAME HALL");
    else DLOG("NOT IN GAME HALL");
}
int main()
{   
    // user_table db(HOST,USER,PASS,DBNAME,PORT);
    // online_manager om;
    // room_manager rm(&db,&om);
    // room_ptr rp=rm.room_create(10,20);
    // matcher mc(&om,&rm,&db);
    gobang_server server(HOST,USER,PASS,DBNAME,PORT);
    server.start(8080);
    return 0;

}